module.exports = function ($scope, $resource, toaster, $stateParams, $modal, class_code) {
    
    $scope.searchform = {};
    $scope.bigCurrentPage = 1;
    $scope.itemsPerPage = 10; 
    var class_code1 = $stateParams.class_code || class_code;

    $scope.load = function () {
        var para = {
            'pageNo': $scope.bigCurrentPage, 
            'pageSize': $scope.itemsPerPage,
            'class_code': class_code1,
            'product_name': $scope.searchform.product_name,
            'product_code': $scope.searchform.product_code,
            'place_name': $scope.searchform.place_name
        }
        $resource('/api/as/mc/shopclass/classProductPageList', {}, {}).save(para, function (res) {
            if (res.errcode === 0) {
                $scope.classProductList = res.data.results;
                $scope.bigTotalItems = res.data.totalRecord;
            } else {
                toaster.error({ title: '', body: res.errmsg });
            }
        });
    }
    $scope.load();

    //添加分类下产品
    $scope.save = function () {
        var modalInstance = $modal.open({
          template: require('../views/skwxAddClassProduct.html'),
          controller: 'skwxAddClassProduct',
          size: 'lg',
          resolve: {
            'class_code': function () {
              return class_code1;
            }
          }
        });
        //关闭模态框刷新页面
        modalInstance.result.then(function () {
          $scope.load();
        });
    }

    //删除分类下产品
    $scope.delete = function (index) {
        let para = {
            class_code: class_code1,
            product_code: $scope.classProductList[index].product_code
        }
        $resource('/api/as/mc/shopclass/deleteClassProduct', {}, {}).save(para, function (res) {
            if (res.errcode === 0) {
                toaster.success({ title: '', body: '操作成功' });
                $scope.load();
            } else {
                toaster.error({ title: '', body: res.errmsg });
            }
        });
    }

    //保存
    $scope.saveone = function (info) {
        $resource('/api/as/mc/shopclass/updateClassProduct', {}, {}).save(info, function (res) {
            if (res.errcode === 0) {
                toaster.success({ title: '', body: '操作成功' });
                $scope.load();
            } else {
                toaster.error({ title: '', body: res.errmsg });
            }
        });
    }

    //取消
    $scope.close = function () {
        $modalInstance.dismiss('cancel');
    }

};